#! /bin/bash
kv4cj_path=$(cd `dirname $0`; pwd)
#kv4cj_path=$(pwd)


# check libcore.so
if [ ! -d "${kv4cj_path}/lib/" ];then
    mkdir ${kv4cj_path}/lib
    echo "Please copy libcore.so to the folder ${kv4cj_path}/lib."
    exit 1
fi

if [ ! -f "${kv4cj_path}/lib/libcore.so" ];then
    echo "Please copy libcore.so to the folder ${kv4cj_path}/lib."
    exit 1
fi

# libmymmkv.so
cd ${kv4cj_path}/mmkv_cpp
if [ -f "Makefile" ];then
    make clean
fi

if [[ -n $(uname -a|grep "aarch64") ]];then
    ./configure
else
    ./configure --cc="aarch64-linux-gnu-g++" --cross-prefix="aarch64-linux-gnu-"
fi
make

# kv4cj
cd  ${kv4cj_path}/
echo start build kv4cj
cjpm build -V
cp ${kv4cj_path}/lib/*.so ${kv4cj_path}/target/release/kv4cj/
echo end build kv4cj
